~ chicken-core (master) /manual/Module (chicken io)


  1[[tags: manual]]
  2[[toc:]]
  3
  4== Module (chicken io)
  5
  6This module provides various Input/Output extensions.
  7
  8=== read-list
  9
 10<procedure>(read-list [PORT [READER [MAX]]])</procedure>
 11
 12Call {{READER}} up to {{MAX}} times and collect its output in a list. If {{MAX}} is {{#f}}, read until end of file.
 13
 14The reader is called with one argument: {{PORT}}.
 15
 16{{READER}} defaults to {{read}}, {{MAX}} to {{#f}} and {{PORT}} to {{current-input-port}}, so if you call it with no arguments, it will read all remaining s-expressions from the current input port.
 17
 18
 19=== read-byte
 20=== write-byte
 21
 22<procedure>(read-byte [PORT])</procedure><br>
 23<procedure>(write-byte BYTE [PORT])</procedure>
 24
 25Read/write a byte to the port given in {{PORT}}, which default to the values
 26of {{(current-input-port)}} and {{(current-output-port)}}, respectively.
 27
 28
 29=== read-line
 30=== write-line
 31
 32<procedure>(read-line [PORT [LIMIT]])</procedure><br>
 33<procedure>(write-line STRING [PORT])</procedure>
 34
 35Line-input and -output. {{PORT}} defaults to the value of
 36{{(current-input-port)}} and {{(current-output-port)}},
 37respectively. If the optional argument {{LIMIT}} is given and
 38not {{#f}}, then {{read-line}} reads at most {{LIMIT}}
 39characters per line. {{read-line}} returns a string without the terminating newline and {{write-line}} adds a terminating newline  before outputting.
 40
 41
 42=== read-lines
 43
 44<procedure>(read-lines [PORT [MAX]])</procedure>
 45
 46Read {{MAX}} or fewer lines from {{PORT}}. {{MAX}} defaults to
 47{{most-positive-fixnum}} and {{PORT}} defaults to the value of
 48{{(current-input-port)}}. Returns a list of strings, each string
 49representing a line read, not including any line separation
 50character(s).
 51
 52
 53=== read-string
 54=== read-string!
 55
 56<procedure>(read-string [NUM [PORT]])</procedure><br>
 57<procedure>(read-string! NUM STRING [PORT [START]])</procedure><br>
 58
 59Read or write {{NUM}} characters from/to {{PORT}}, which defaults to the
 60value of {{(current-input-port)}} or {{(current-output-port)}}, respectively.
 61
 62If {{NUM}} is {{#f}} or not given, then all data up to the end-of-file is
 63read, or, in the case of {{write-string}} the whole string is written. If no
 64more input is available, {{read-string}} returns {{#!eof}}.
 65
 66{{read-string!}} reads destructively into the given {{STRING}} argument, but
 67never more characters than would fit into {{STRING}}. If {{START}} is given,
 68then the read characters are stored starting at that position.
 69{{read-string!}} returns the actual number of characters read.
 70
 71
 72=== read-bytevector
 73
 74<procedure>(read-bytevector [NUM [PORT]])</procedure>
 75
 76Read {{NUM}} bytes from {{PORT}}, which defaults to the
 77value of {{(current-input-port)}}. {{read-bytevector}} allocates
 78a new buffer and returns it (or the end-of-file object, if at the end
 79of the input file).
 80
 81If {{NUM}} is optional and not given, then all remaining input is read
 82or the whole bytevector is read/written.
 83
 84=== read-bytevector!
 85
 86<procedure>(read-bytevector! BYTEVECTOR [PORT START END])</procedure>
 87
 88Read bytes from {{PORT}} into {{BYTEVECTOR}}. {{PORT}} defaults to the
 89value of {{(current-input-port)}} and returns the actual number of bytes read.
 90
 91{{START}} and {{END}} designate the range of bytes that should be filled
 92with input from {{PORT}}. If {{END}} exceeeds the length of {{BYTEVECTOR}}
 93only as much data is read as fits into the destination buffer.
 94
 95=== write-bytevector
 96
 97<procedure>(write-bytevector BYTEVECTOR [PORT START END])</procedure>
 98
 99Write bytes from {{BYTEVECTOR}} to {{PORT}}. {{PORT}} defaults to the
100value of {{(current-output-port)}}.
101
102{{START}} and {{END}} designate the range of bytes that should be written.
103If {{END}} exceeeds the length of {{BYTEVECTOR}}
104only as much data is written as is available.
105
106
107=== read-token
108
109<procedure>(read-token PREDICATE [PORT])</procedure>
110
111Reads characters from {{PORT}} (which defaults to the value of {{(current-input-port)}})
112and calls the procedure {{PREDICATE}} with each character until {{PREDICATE}} returns
113false. Returns a string with the accumulated characters.
114
115---
116Previous: [[Module (chicken gc)]]
117
118Next: [[Module (chicken irregex)]]
Trap